/********************************************************************
	created:	2011/04/24
	created:	24:4:2011   18:51
	filename: 	d:\Work\Job\trunk\Speed\SmallDialog.cpp
	file path:	d:\Work\Job\trunk\Speed
	file base:	SmallDialog
	file ext:	cpp
	author:		liang
	
	purpose:	
*********************************************************************/
#include "SmallDialog.h"

SmallDialog::SmallDialog(QWidget* pParent)
:QDialog(pParent)
{
	//
	Qt::WindowFlags flags = Qt::Window |
							Qt::FramelessWindowHint|
							//Qt::WindowTitleHint | 
							Qt::WindowCloseButtonHint |
							Qt::WindowStaysOnTopHint;

	setWindowFlags(flags);

	int _width = qApp->desktop()->rect().width();
	int _height = qApp->desktop()->rect().height();

	move(_width - 180,30);
	m_smallDialog.setupUi(this);

	setMouseTracking(true);
	m_bEnter = false;
}

SmallDialog::~SmallDialog()
{

}

static int lx =0;
static int ly =0;
#include <windows.h>
void SmallDialog::mouseMoveEvent(QMouseEvent* pEvent)
{
	if (pEvent)
	{
		//if(pEvent->button() == Qt::LeftButton)
		if(m_bEnter)
		{
			int gx = pEvent->globalX();
			int gy = pEvent->globalY();

			move(gx - lx,gy - ly);
		}
	}
}

void SmallDialog::mousePressEvent(QMouseEvent* pEvent)
{
	if (pEvent)
	{
		if(pEvent->button() == Qt::LeftButton)
		{
			lx = pEvent->x();
			ly = pEvent->y();

			m_bEnter = true;
		}
	}
}

void SmallDialog::mouseReleaseEvent(QMouseEvent* pEvent)
{
	if (pEvent)
	{
		if(pEvent->button() == Qt::LeftButton)
		{
			m_bEnter = false;
		}
	}
}